<%--
  Created by IntelliJ IDEA.
  User: WanMing
  Date: 2019/2/7
  Time: 18:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加操作员</title>

    <script type="text/javascript" src="${ctx}/resources/layui/layui.js"></script>
</head>
<body>


<form class="layui-form" action="" id="forData">
    <div class="layui-form-item" style=>
        <div class="layui-inline" style="width: 40%">
            <label class="layui-form-label">操作员ID:</label>
            <div class="layui-input-inline">
                <input type="tel" name="operatorId"  placeholder="请输入操作员ID" autocomplete="off" class="layui-input" style="width: 400px">
            </div>
        </div>
        <div class="layui-inline" style="width: 40%">
            <label class="layui-form-label">操作员姓名:</label>
            <div class="layui-input-inline">
                <input type="text" name="operatorName" id="operatorName" placeholder="请输入操作员姓名" autocomplete="off" class="layui-input" style="width: 400px">
            </div>
        </div>

        <div class="layui-inline" style="width: 40%">
            <label class="layui-form-label">密码:</label>
            <div class="layui-input-inline">
                <input type="password" name="operatorPwd" id="operatorPwd" placeholder="请输入操作员密码" autocomplete="off" class="layui-input" style="width: 400px">
            </div>
        </div>

        <div class="layui-inline" style="width: 40%">
            <label class="layui-form-label">确认密码:</label>
            <div class="layui-input-inline">
                <input type="password" name="reOperatorPwd" id="reOperatorPwd" placeholder="请输入确认密码" autocomplete="off" class="layui-input" style="width: 400px">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">权限：</label>
            <div class="layui-input-block">
               管理员: <input type="radio" name="isAdmin" value="Y" title="管理员" >
               操作员: <input type="radio" name="isAdmin" value="N" title="操作员" checked="">
            </div>
        </div>

    </div>
</form>

<%--注意此处的按钮应该放在表单外面，防止两次表单提交的影响--%>
<div class="layui-form-item">
    <div class="layui-input-block" style="text-align: center">
        <button class="layui-btn" id="butSubmit">提交</button>
        <button type="reset" class="layui-btn layui-btn-primary" id="resetOperator">重置</button>
    </div>
</div>


<script>

    layui.use(['layer','jquery'],function () {
        var layer = layui.layer;
        var $ = layui.jquery;



        //提交表单
        $("#butSubmit").click(function () {

            $.ajax({
                url:"${ctx}/operator/addOperator.action",
                type:"post",
                data:$("#forData").serialize(),
                dataType:"text",
                success:function (obj) {

                    if(obj.code==1){
                        console.log("添加成功");
                    }
                },
                error:function (xhr,text) {
                    console.log(text);
                },
                complete:function (xhr,text) {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                    parent.location.href="${ctx}/operator/toLoadAllOperator.action";
                }
            });
        });


    });

</script>
</body>
</html>
